package com.MedDroid.entities.database;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: Romen
 * Date: 28/11/13
 * Time: 1:59 PM
 * Description: Represents a row in the database, can contain any number of Field objects
 */
public class DatabaseRow
{
	int RowIndex;
	String Label;
	ArrayList<DatabaseField> Fields;

	public DatabaseRow(int Index, String Label)
	{
		this.RowIndex = Index;
		this.Label = Label;
		Fields = new ArrayList<DatabaseField>();
	}

	public void setIndex(int Index)
	{
		RowIndex = Index;
	}

	public String getLabel()
	{
		return Label;
	}

	public void addField(DatabaseField Field)
	{
		Fields.add(Field);
	}

	public void removeField(DatabaseField Field)
	{
		Fields.remove(Field);
	}

	public void removeField(String FieldName)
	{
		for (DatabaseField F : Fields)
		{
			if (F.getName().equals(FieldName))
			{
				Fields.remove(F);
			}
		}
	}

	public DatabaseField getField(String FieldName)
	{
		for (DatabaseField Field : Fields)
		{
			if (Field.getName().equals(FieldName))
			{
				return Field;
			}
		}
		return null;
	}

	public String getValue(String FieldName)
	{
		for (DatabaseField Field : Fields)
		{
			if (Field.getName().equalsIgnoreCase(FieldName))
			{
				return Field.getValue();
			}
		}

		return "";
	}

	public int getSize()
	{
		return Fields.size();
	}

	public ArrayList<DatabaseField> getFields()
	{
		return Fields;
	}

	public void encrypt()
	{
		for (DatabaseField F : Fields)
		{
			F.encrypt();
		}
	}

	public void decrypt()
	{
		for (DatabaseField F : Fields)
		{
			F.decrypt();
		}
	}
}
